package com.xinyue.cross.server.server;

import com.xinyue.game.message.GameMessageType;
import com.xinyue.game.message.GameServerMessageModel;
import com.xinyue.game.message.GameServerRequestHeader;
import com.xinyue.game.message.GameServerResponseHeader;

public class ServerResponseService {

    private static GameServerResponseHeader createResponseHeader(GameServerRequestHeader requestHeader, int errorCode, String errorMsg) {
        GameServerResponseHeader responseHeader = new GameServerResponseHeader();
        responseHeader.setResponseTime(System.currentTimeMillis());
        responseHeader.setErrorMsg(errorMsg);
        responseHeader.setErrorCode(errorCode);
        responseHeader.setRequestId(requestHeader.getRequestId());
        responseHeader.setUserKey(requestHeader.getUserKey());
        responseHeader.setRequestUri(requestHeader.getRequestUri());
        responseHeader.setMessageType(GameMessageType.RESPONSE.getType());
        return responseHeader;
    }

    public static GameServerMessageModel<GameServerResponseHeader> createResponseModel(GameServerRequestHeader requestHeader, int errorCode, String errorMsg) {
        GameServerResponseHeader responseHeader = createResponseHeader(requestHeader, errorCode, errorMsg);
        GameServerMessageModel<GameServerResponseHeader> messageModel = new GameServerMessageModel<>();
        messageModel.setHeader(responseHeader);
        return messageModel;
    }

    public static GameServerMessageModel<GameServerResponseHeader> createResponseModel(GameServerRequestHeader requestHeader) {
        return createResponseModel(requestHeader, 0, null);
    }
}
